home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Logiciels PC 18
/
LOGICIELSPC_18.ISO
/
Accuses
/
MAJ
/
Rtf2Html
/
Source C
/
RTFPARSE
/
MPARSE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-27
|
8KB
|
319 lines
/*
* %%File: mparse.c
*
* Copyright (c) 1995-1999 Bertrand LE QUELLEC
*
* http://perso.wanadoo.fr/blq
* blq@wanadoo.fr
*/
#define STRICT
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include "rtftype.h"
#include "rtfdecl.h"
#include "rtfreadr.h"
#include "rtfparse.h"
#include "html.h"
#define SOURCE_MAIN 1
#include "mparse.h"
static void InitVariable (void)
{
nbFigure = 0;
prefigure[0] = '\0';
flagTableau = carcell = nbcell = oldnbcell = 0;
cellule[0] = '\0';
plusNiveau = fontSize = 0;
oldProp = tagCenter = tagUL = tagTR = tagLI = tagDD = flagDD = 0;
flagHeader = flagGO = flagTOC = flagREF = 0;
crochet = valCrochetF = valCrochetH = 0;
flagFootnote = nbFootnote = 0;
nbcar = 0;
lesCar[0] = '\0';
nbBk = flagBKMK = 0;
lesBkmk[0] = '\0';
styleBold = styleItalic = valCrochetB = valCrochetI = 0;
niveau = oldNiveau = carniv = 0;
leNiveau[0] = '\0';
carnot = 0;
Notes[0] = lesNotes[0][0] = '\0';
nbnote = flagNote = flagPnText = nbResult = flagFldrslt = 0;
Fldrslt[0] = '\0';
cGroup = flagStop = nbUrl = 0;
Url[0] = '\0';
flagBR_P = flagFRAME = 0;
cbBin = lParam = 0L;
fSkipDestIfUnk = 0;
}
/* ------------------- VISUAL C++ ------------------------------------------ */
int _export _pascal
RtfToHTML(char * fichier_rtf, char * fichier_html,
int EnteteFichier, int FinFichier, char * prefixe,
char * titreFichier, char * couleur, char * image, int br_p, int frame)
{
FILE * fpIndex = (FILE *)0;
int retour = ecOK, ct = 0, ct1 = 0, flag = 0;
InitVariable ();
/* --- */
if(!strlen(fichier_rtf) || !fichier_rtf)
return errfRTF;
if(!(fpIn = (FILE *)fopen(fichier_rtf, "r")))
return erroRTF;
/* --- */
if(!strlen(fichier_html) || !fichier_html)
return errfHTML;
if(!(fpIndex = (FILE *)fopen(fichier_html, "w")))
{
fclose(fpIn);
return erroHTML;
}
/* FRAME */
flagFRAME = frame;
if (flagFRAME)
{
if ((int)strlen(fichier_html) < MLEN*2)
{
for (ct = 0; ct < (int)strlen(fichier_html); ct++)
{
if (fichier_html[ct] == '.') break;
if (fichier_html[ct] == '\\')
flag = 0;
else
flag++;
pageFile [ct] = fichier_html[ct];
tableFile [ct] = fichier_html[ct];
noteFile [ct] = fichier_html[ct];
}
if (flag > 5) ct = ct - 3;
}
pageFile [ct] = '\0';
tableFile [ct] = '\0';
noteFile [ct] = '\0';
sprintf(pageFile, "%s%s", pageFile, PAGE_FILE);
sprintf(tableFile, "%s%s", tableFile, TABLE_FILE);
sprintf(noteFile, "%s%s", noteFile, NOTE_FILE);
/* --- */
if(!(fpOut = (FILE *)fopen(pageFile, "w")))
{
fclose(fpIn);
return erroHTML;
}
if(!(fpTable = (FILE *)fopen(tableFile, "w")))
{
fclose (fpIn);
fclose (fpOut);
return erroHTML;
}
if(!(fpNote = (FILE *)fopen(noteFile, "w")))
{
fclose (fpIn);
fclose (fpOut);
fclose (fpTable);
return erroHTML;
}
if ((int)strlen(fichier_html) < MLEN*2)
{
pageFile [0] = '\0';
tableFile [0] = '\0';
noteFile [0] = '\0';
for (ct = (int)strlen(fichier_html); ct >= 0; ct--)
{
if (fichier_html[ct] == '\\')
{
ct++;
break;
}
}
for (ct1 = 0; ct < (int)strlen(fichier_html); ct++, ct1++)
{
if (fichier_html[ct] == '.') break;
pageFile [ct1] = fichier_html[ct];
tableFile [ct1] = fichier_html[ct];
noteFile [ct1] = fichier_html[ct];
}
if (flag > 5) ct1 = ct1 - 3;
pageFile [ct1] = '\0';
tableFile [ct1] = '\0';
noteFile [ct1] = '\0';
sprintf(pageFile, "%s%s", pageFile, PAGE_FILE);
sprintf(tableFile, "%s%s", tableFile, TABLE_FILE);
sprintf(noteFile, "%s%s", noteFile, NOTE_FILE);
}
}
else
fpOut = fpIndex;
/* PREFIXE FIGURE */
if(prefixe && strlen(prefixe))
sprintf(prefigure, "%s", prefixe);
else
sprintf(prefigure, "figure");
/* ENTETE */
if(EnteteFichier)
{
EnteteHTML(TAG_RTFTOHTML, fpOut);
if (flagFRAME)
{
EnteteHTML(TAG_RTFTOHTML, fpTable);
EnteteHTML(TAG_RTFTOHTML, fpNote);
}
}
/* TITRE */
if(strlen(titreFichier) && titreFichier)
{
TitreHTML(titreFichier, fpOut);
if (flagFRAME)
{
TitreHTML("Table des matières", fpTable);
TitreHTML("Notes de bas de page", fpNote);
}
}
/* BGCOLOR */
if (strlen(couleur) && couleur)
{
BgColorHTML(couleur, fpOut);
if (flagFRAME)
{
BgColorHTML(couleur, fpTable);
BgColorHTML(couleur, fpNote);
}
}
/* BACKGROUND */
if(strlen(image) && image)
{
BackgroundHTML(image, fpOut);
if (flagFRAME)
{
BackgroundHTML(image, fpTable);
BackgroundHTML(image, fpNote);
}
}
/* BR ou P */
flagBR_P = br_p;
if (flagFRAME)
{
fprintf(fpTable, "<H3>Table des matières</H3>");
fprintf(fpNote, "<H3>Notes de bas de page</H3>");
}
/* ------------------------
* Lancement du parseur : */
retour = ecRtfParse(fpIn);
if(FinFichier)
{
fprintf(fpOut, "\n%s%s", TAGf_BODY, TAGf_HTML);
if (flagFRAME)
{
fprintf(fpTable, "\n%s%s", TAGf_BODY, TAGf_HTML);
fprintf(fpNote, "\n%s%s", TAGf_BODY, TAGf_HTML);
}
}
fflush(fpOut);
if (flagFRAME)
{
fflush(fpTable);
fflush(fpNote);
fclose (fpTable);
fclose (fpNote);
}
fclose (fpIn);
fclose (fpOut);
if (!flagFRAME) return retour;
/* --- */
fprintf(fpIndex, "%s\n%s\n%s\n%s\n", TAG_HTML, TAG_HEAD, TAG_RTFTOHTML, TAGf_HEAD);
if (flagNote > 0)
{
fprintf(fpIndex, "<FRAMESET ROWS=\"85%%,15%%\" NAME=\"principal\"\nFRAMEBORDER=\"NO\" FRAMESPACING=0 BORDER=1 SCROLLING=\"auto\">\n");
fprintf(fpIndex, "<FRAMESET COLS=\"30%%,70%%\" NAME=\"document\"\nFRAMEBORDER=\"NO\" FRAMESPACING=0 BORDER=0 SCROLLING=\"auto\">\n");
fprintf(fpIndex, "\t<FRAME SRC=\"%s\" NAME=\"%s\">\n", tableFile, TABLE_FRAME);
fprintf(fpIndex, "\t<FRAME SRC=\"%s\" NAME=\"%s\">\n</FRAMESET>\n", pageFile, PAGE_FRAME);
fprintf(fpIndex, "\t<FRAME SRC=\"%s\" NAME=\"%s\">\n</FRAMESET>\n", noteFile, NOTE_FRAME);
}
else
{
fprintf(fpIndex, "<FRAMESET COLS=\"30%%,70%%\" NAME=\"principal\"\nFRAMEBORDER=\"NO\" FRAMESPACING=0 BORDER=0 SCROLLING=\"auto\">\n");
fprintf(fpIndex, "\t<FRAME SRC=\"%s\" NAME=\"%s\">\n", tableFile, TABLE_FRAME);
fprintf(fpIndex, "\t<FRAME SRC=\"%s\" NAME=\"%s\">\n</FRAMESET>\n", pageFile, PAGE_FRAME);
}
fprintf(fpIndex, "\n%s\n", TAGf_HTML);
fflush (fpIndex);
fclose (fpIndex);
return retour;
}